package com.zxx.pattern.iteratorPattern.iterator2;

import com.zxx.pattern.iteratorPattern.iterator2.old.MenuItem;

import java.util.List;

/**
 * 电视界面的迭代器
 * @author zxx on 2021/4/8
 */
public class TVChanneMenuIterator implements Iterator2 {

    List<MenuItem> menuItems;
    int position = 0;

    public TVChanneMenuIterator(List<MenuItem> menuItems) {
        this.menuItems = menuItems;
    }

    @Override
    public boolean hasNext() {
        if (position > menuItems.size() - 1 || menuItems.get(position) == null) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public Object next() {
        MenuItem menuItem = menuItems.get(position);
        position ++;
        return menuItem;
    }
}
